package com.wenwei.sharebox.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wenwei.sharebox.R;
import com.wenwei.sharebox.bean.GoodCateBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/7.
 */
public class CateGoryLeftAdapter extends RecyclerView.Adapter<CateGoryLeftAdapter.MyViewHolder> {

    private int mCurrentSelectPos = 0;//默认为选中第一个分类
    private LeftCallBack mCallBack;

    private ArrayList<GoodCateBean> mList;
    public void setDataList(ArrayList<GoodCateBean> list){
        this.mList = list;
    }

    public CateGoryLeftAdapter(LeftCallBack callBack){
        this.mCallBack = callBack;
    }


    public interface LeftCallBack{
        void onLeftItemClick(List<GoodCateBean.ShopTweClassesBean> list);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_category_left, null));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCurrentSelectPos = position;
                mCallBack.onLeftItemClick(mList.get(position).getShopTweClasses());
                notifyDataSetChanged();
            }
        });
        holder.mainText.setText(mList.get(position).getName());
        if(mCurrentSelectPos == position){
            holder.mainLl.setBackgroundColor(Color.parseColor("#ffffff"));
            holder.mainText.setTextColor(Color.parseColor("#40CCCB"));
            holder.mainView.setVisibility(View.VISIBLE);
        }else{
            holder.mainLl.setBackgroundColor(Color.parseColor("#e9e9e9"));
            holder.mainText.setTextColor(Color.parseColor("#333333"));
            holder.mainView.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.main_view)
        View mainView;
        @Bind(R.id.main_text)
        TextView mainText;
        @Bind(R.id.main_ll)
        RelativeLayout mainLl;
        public MyViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
